﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

// This is the initial jQuery starting point.  The 'main' function is run once the DOM of every page is established.



  // This function must be called with all modal dialog boxes which have fields that
  // require validation.  It performs a call to the ASP.Net function, "Page_ClientValidate()",
  // and then continues on calling "CloseModalDialog()" if the validation is okay.
  // Note: Surprisingly, companion functions like "ValidatorValidate()" do not work, 
  // perhaps due to the way ThickBox rearranges DOM elements.
  function CheckValidationBeforeClose(element) {
    if (Page_ClientValidate())
      CloseModalDialog(element);
  }


  // Used to close a ThickBox modal dialog and then force a postback,
  // which a server-side control is seemingly unable to do on its own
  // when fired from within the confines of a ThickBox object.
  function CloseModalDialog(element) {
    tb_remove();
    setTimeout('__doPostBack(\'' + element.name + '\',\'\')', 500);  // 500ms seems to give ThickBox enough time to remove itself
  }


  // Used to close a ThickBox modal dialog without causing a postback.
  function CancelModalDialog() {
    tb_remove();
  }



  // Prepares all textboxes such that the background changes to a distinct
  // color upon focus and then returns to white after focus is lost.
  function PrepareDefaultEventHandlers() {
    $(":text").focus(textboxHighlight).blur(textboxRemoveHighlight);
    $(":password").focus(textboxHighlight).blur(textboxRemoveHighlight);
    $("textarea").focus(textboxHighlight).blur(textboxRemoveHighlight);
  }

  function textboxHighlight() {
    $("#" + this.id).css({ 'background-color': '#ffff40' });
  }

  function textboxRemoveHighlight() {
    $("#" + this.id).css({ 'background-color': 'white' });
}
// Format Copy content from Word
function removeTextFormat(ControlID) 
{   
         
        var  CuteEditor =  document.getElementById(ControlID);
        var mystring = CuteEditor.getHTML();
        
        var reRemoveHTMLComment = /<(?:!(?:--[\s\S]*?--\s*)?(>)\s*|(?:script|style)[\s\S]*?<\/(?:script|style)>)/gi;
        var reRemoveTag = /<[/\?]?(font|a|xml|h1|h2|h3|h4|h5|h6|h7|h8|b|strong|em|del|ins|st\d+\:[\w\-]+|[ovwxp]:\w+)[^>]*?>/gi;
        var reGetAnyTag = /(<[^>]+>)/gi;
        var clearStyle = /(style=".*?")/gi;
        var clearClass = /(class=".*?")/gi;
        var reRemoveAttribute = /(?:class|style|lang|name|alt|id|href|border|target|size|face|on\w+|[ovwxp]:\w+)(?:\=(?:'[^']*'|"[^"]*"|[^\s>]+|)|[\s])/gi;
        mystring = mystring.replace(clearClass,'');
        mystring = mystring.replace(clearStyle,'');
        mystring = mystring.replace(reRemoveHTMLComment, function(m,$1){return $1?'':m;});
        mystring = mystring.replace(reRemoveTag, '');
        mystring = mystring.replace(reGetAnyTag, function($1){isTable=$1.match(/^<table(?=\s|>)/gi); return $1.replace(reRemoveAttribute, function($2){
                                var arr = $2.split('=');
                                var attr = arr[0];
                                var value = arr[1]?arr[1]:'';

                                if (attr.toLowerCase() == 'style' && value != '' && value != '""' && value != "''")
                                {
                                            var reChangeStyleAttr = /(\s*(?:mso[^:]*|-moz-[^:]*|color|background[^:]*|font[^:]*|border[^:]*)[\s]*:[^;]*(;|(?='|"))|(?=;|'|"|)\s*[^:]+;;)/gi;

                                            onlyOne=true;
                                            value = value.replace(reChangeStyleAttr, function($3){
                                                                    if ($3.match(/^\s*border[^:]*:/gi) && isTable && onlyOne)
                                                                    {
                                                                                onlyOne=false; 
                                                                                return 'border-collapse: collapse;';
                                                                    }
                                                                    else return '';
                                                                                                                                                                                                        });

                                            if (value != '""' && value != "''") return 'style=' + value;
                                            else return ''
                                }
                                else if (attr.toLowerCase() == 'border' && value != '0' && value != '"0"' && value != "'0'")
                                {
                                            return 'border=' + value + ' bordercolor="black" style="border-collapse: collapse;" ';
                                }
                                else return '';
        });});
        

    mystring = mystring.replace("<img ", "<img class='center' " );
        
   CuteEditor.setHTML(mystring) ;
}

// check all and uncheck all for GridView
// date add: 21/02/2011
function CheckAll(e) {
        var xState = e.checked;
        var theBox = e;
        var elm = theBox.form.elements;
        var i = 0;
        for (i = 0; i < elm.length; i++)
            if (elm[i].type == "checkbox" && elm[i].id != theBox.id)
                if (elm[i].checked != xState && !elm[i].disable)
                    elm[i].click();
    }

function getLog() {
    var CountClass = $(".DivLabel").length;
    var valText = "";
    var valValue = "";
    for (var i = 0; i < CountClass; i++) {
        valText = valText + ($(".DivLabel").eq(i).find("span").html() + ";");
        if ($(".DivTextBox").eq(i).find("input").length != 0) {
            valValue = valValue + ($(".DivTextBox").eq(i).find("input").val() + ";");
        }
        if ($(".DivTextBox").eq(i).find("select").length != 0) {
            valValue = valValue + ($(".DivTextBox").eq(i).find('option:selected').val() + ";");
        }
    }
getValueLog(valValue);
getTextLog(valText);
}
function getValueLog(Value) {
    return Value;
}
function getTextLog(Text) {
    return Text;
}